package com.example.mcdonaldapplication.info

import android.app.Activity
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.mcdonaldapplication.R
import com.example.mcdonaldapplication.activity.GiveTicketActivity
import com.example.mcdonaldapplication.activity.OrderActivity

class TicketAdapter(private val mutableList: MutableList<TicketInfo>, private val context: Activity) : RecyclerView.Adapter<TicketAdapter.ViewHolder>(){

    class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView){
        val tvTicketContent: TextView = itemView.findViewById(R.id.tvTicketContent)
        val tvTicketMoney: TextView = itemView.findViewById(R.id.tvTicketMoney)
        val btnGiveToFriend: android.widget.Button = itemView.findViewById(R.id.btnGiveToFriend)
        val btnUse: android.widget.Button = itemView.findViewById(R.id.btnUse)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.ticket_item,parent,false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val data = mutableList[position]
        holder.tvTicketContent.text = data.content
        holder.tvTicketMoney.text = data.lines
//        holder.tvTrashImage.setImageResource(data.image)

        holder.btnGiveToFriend.setOnClickListener{
            val intent = Intent(context, GiveTicketActivity::class.java)
            context.startActivity(intent)
        }

        holder.btnUse.setOnClickListener{
            val intent = Intent(context, OrderActivity::class.java)
            context.startActivity(intent)
        }

    }

    override fun getItemCount(): Int {
        return mutableList.size
    }
}
